change this to only emit a warning right now
authorPaul Woolcock <paul@woolcock.us>
Tue, 6 Dec 2016 15:07:52 +0000 (10:07 -0500)
committerPaul Woolcock <paul@woolcock.us>
Tue, 6 Dec 2016 20:51:06 +0000 (15:51 -0500)
src/cargo/util/toml.rs
tests/build-script.rs

index fd5a36ca1f9b10eb3eea43c579815e0f9fd8023e..18b4d4c6cfc0a1b109cd7cd2ae845f105c5d19b7 100644 (file)
@@ -546,7 +546,7 @@ impl TomlManifest {
         }
 
         // processing the custom build script
-        let new_build = self.maybe_custom_build(&project.build, &layout.root);
+        let new_build = self.maybe_custom_build(&project.build, &layout.root, &mut warnings);
 
         // Get targets
         let targets = normalize(&lib,
@@ -774,7 +774,10 @@ impl TomlManifest {
         Ok(replace)
     }
 
-    fn maybe_custom_build(&self, build: &Option<StringOrBool>, project_dir: &Path)
+    fn maybe_custom_build(&self,
+                          build: &Option<StringOrBool>,
+                          project_dir: &Path,
+                          warnings: &mut Vec<String>)
                           -> Option<PathBuf> {
         let build_rs = project_dir.join("build.rs");
         match *build {
@@ -783,7 +786,15 @@ impl TomlManifest {
             Some(StringOrBool::String(ref s)) => Some(PathBuf::from(s)),
             None => {
                 match fs::metadata(&build_rs) {
-                    Ok(ref e) if e.is_file() => Some(build_rs.into()),
+                    // Enable this after the warning has been visible for some time
+                    // Ok(ref e) if e.is_file() => Some(build_rs.into()),
+                    Ok(ref e) if e.is_file() => {
+                        warnings.push("`build.rs` files in the same directory \
+                                       as your `Cargo.toml` will soon be treated \
+                                       as build scripts. Add `build = false` to \
+                                       your `Cargo.toml` to prevent this".into());
+                        None
+                    },
                     Ok(_) => None,
                     Err(_) => None,
                 }
index 021ea084245367b94a778290ae29f7ba923a2aa3..01ea55f9a51e32686e76c2b2a6de01091d314318 100644 (file)
@@ -2345,8 +2345,12 @@ fn assume_build_script_when_build_rs_present() {
             authors = []
         "#)
         .file("src/main.rs", r#"
+            use std::path::Path;
             fn main() {
-                println!(include_str!(concat!(env!("OUT_DIR"), "/output")));
+                let f = env!("OUT_DIR");
+                assert!(
+                    ! Path::new(f).join("output").exists()
+                );
             }
         "#)
         .file("build.rs", r#"
@@ -2365,7 +2369,14 @@ fn assume_build_script_when_build_rs_present() {
     p.build();
 
     assert_that(p.cargo("run").arg("-v"),
-                execs().with_status(0).with_stdout("foo\n"));
+                execs().with_status(0).with_stderr("\
+warning: `build.rs` files in the same directory as your `Cargo.toml` will soon be treated \
+as build scripts. Add `build = false` to your `Cargo.toml` to prevent this
+   Compiling builder v0.0.1 ([..])
+     Running [..]
+    Finished [..]
+     Running [..]
+"));
 }
 
 #[test]